package org.glut.wechat.addresslist.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.glut.wechat.addresslist.entity.Relation;
import org.glut.wechat.addresslist.entity.User;
import org.glut.wechat.addresslist.mapper.RelationMapper;
import org.glut.wechat.addresslist.mapper.UserMapper;
import org.glut.wechat.addresslist.service.IRelationService;
import org.glut.wechat.addresslist.service.IUserService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 好友表 服务实现类
 *
 * @author harry
 * @since 2025-08-20 21:42
 */
@Service
public class RelationServiceImpl extends ServiceImpl<RelationMapper, Relation> implements IRelationService {

        @Resource
        private RelationMapper relationMapper;
        @Resource
        private IUserService userService;
        @Resource
        private UserMapper userMapper;

        /**
         * 根据用户ID查询好友列表
         * @param userId 本人ID
         * @return 好友信息列表
         */
        public List<User> getFriendsByUserId(Integer userId) {
            // 查询该用户的好友ID列表
            List<Integer> friendIds = relationMapper.selectFriendIdsByUserId(userId);
            if (friendIds == null || friendIds.isEmpty()) {
                return Collections.emptyList();
            }
            return userMapper.selectByIds(friendIds);

    }
    /**
     * 根据好友ID查询详情
     */
    @Override
    public User getFriendDetail(Integer friendId) {
        return userService.getById(friendId);
    }


}
